﻿using Box2DSharp.Collision.Shapes;
using Box2DSharp.Dynamics;
using System;

namespace TrinityEngine
{
    public abstract class Collider2D : Component
    {
        public Body rigidbody;

        public PhysicsMaterial2D material = null;

        public bool isTrigger = false;

        public abstract Shape GetShape();

        protected override void OnEnable()
        {
            if (rigidbody.FixtureList.Count == 0)
            {
                rigidbody.CreateFixture(GetShape(), 1.0f);
            }
        }

        protected override void OnDisable()
        {
            foreach (var f in rigidbody.FixtureList)
            {
                rigidbody.DestroyFixture(f);
            }
        }
    }
}
